package repository

import (
	"git.huoys.com/block_chain/mall/internal/shop/model"
	"git.huoys.com/block_chain/mall/pkg/log"
	"gorm.io/gorm"
)

type ShopRepo interface {
	// 商品
	// 注册商品类别
	CreateClass(name string) (cid uint64, err error)
	// 添加商品
	AddGood(goods model.Goods, addr string) (goodId uint64, err error)
	// 删除商品
	DelGood(goodId uint64) (err error)
	// 修改商品属性
	SetGood(good model.Goods) (err error)
	// 根据分类查找商品
	GetGoodByClass(classId, lastId, limit uint64) (goods []model.Goods, count uint64, err error)
	// 获取分类前几的商品
	GetGoodSByClassSorting(num uint64) (goods []model.Goods, err error)
	// 获取多个商品详情
	GetGoodSByCid(goodsIdS []uint64) (goods []model.Goods, err error)
	// 上传图片地址
	UploadGoodImg(goodId uint64, url string, isMaster bool) (err error)
	// 删除图片地址
	DelGoodImg(goodId, imgId uint64) (err error)
	// 查询图片地址
	GetGoodImg(goodId uint64) (imgs []model.ImgS, err error)
	// 查询商品主图片地址
	GetGoodsImgMasterList(goodSId []uint64) (imgs []model.GoodsImages, err error)
	// 查询商品详细信息
	GetGood(goodsId uint64) (goods model.Goods, err error)
	/****订单相关***/
	// 创建订单
	AddOrder(order model.Order) (id uint64, err error)
	// 修改订单
	SetOrder(order model.Order) (err error)
	// 查询用户订单列表 可以分类
	GetOrderList(uid uint64, status uint64) (orders []model.Order, err error)
	// 获取订单详情
	GetOrder(oid uint64) (orders model.Order, err error)
	// 交易成功，修改订单状态为交易成功，并修改商品信息
	OrderSuccess(goodsId, orderId uint64, addr, orderHash string) (err error)

	Close()
}

type shopRepository struct {
	db  *gorm.DB
	log *log.Logger
}

func NewRepository(db *gorm.DB, log *log.Logger) ShopRepo {
	var a = shopRepository{
		db:  db,
		log: log,
	}
	return &a
}

func (g *shopRepository) Close() {

}
